class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:

        if len(s) <= 1: return len(s)

        char_map, left, ans = dict(), -1, 0
        for i, char in enumerate(s):
            if char not in char_map:
                char_map[char] = i
            else:
                left = max(left, char_map[char])
                char_map[char] = i
            ans = max(ans, i - left)

        return ans


strs=Solution()
s="sssas"
strs.lengthOfLongestSubstring(s)

